﻿@model List<WebApplication5.Models.Task>

@{
    ViewBag.Title = "Index";
}

<h2>Index1</h2>
<table class="table table-striped">
    <thead>
        <tr>
            <th>编号</th>
            <th>内容</th>
            <th>状态</th>
            <th>操作</th>
        </tr>
    </thead>
    <tbody>
        @foreach (var item in Model)
        {

        <tr>
            <td>@item.TaskID</td>
            <td>@item.Content</td>
            <td>@(item.TaskState==1?"未完成":"已完成")</td>
            <td><a href="#" class="btn btn-danger" data-del="@item.TaskID">删除</a><a href="Detail?id=@item.TaskID" class="btn btn-primary">详情</a></td>
        </tr>
        }

    </tbody>
</table>

@section scripts{
    <script type="text/javascript">
        $(function () {
            $("a[data-del]").click(function () {
                var $this = $(this);
                var id = $(this).attr("data-del");
                if (!confirm("你确定要删除吗"+id+"?")) return; 
                $.post("Delete", { id: id }, function (res) {
                    if (res == true) {
                        $this.closest("tr").remove();
                        alert("删除成功");

                    }
                });
            })
        })
    </script>
    
    }